package com.xxwy.link.practice.leetcode;

/**
 * @author xxwy
 */
public class DeleteLinkedNode2 {
    public ListNode removeElements(ListNode head, int val) {
        //使用虚拟头结点，不再对头结点特殊处理,他的取值不在考虑的范围，所以随便取
        ListNode dummyHead = new ListNode(-1);
        dummyHead.next = head;
        //要删除结点的头结点
        ListNode prev = dummyHead;
        while (prev.next != null) {
            if (prev.next.val == val) {
                ListNode delNode = prev.next;
                prev.next = prev.next.next;
                delNode.next = null;
            } else {
                prev = prev.next;
            }

        }
        return dummyHead.next;

    }
}
